{% extends 'base.twig' %}
{% block style %}
    <style>
        .table thead tr th{
            height:30px; line-height: 30px; text-align: center;}
        .table tbody tr td{
            height:30px; line-height: 30px; text-align: center;}
        .file {
            position: relative;
            display: inline-block;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            text-decoration: none;
            text-indent: 0;
            line-height: 24px;
        }
        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }
        .file:hover {
            text-decoration: none;
        }
    </style>
    <link href="template/plugins/pnotify/css/pnotify.custom.css" rel="stylesheet" type="text/css">
    <script src="template/plugins/pnotify/js/pnotify.custom.js" type="text/javascript"></script>
{% endblock %}
{% block content %}
<section id="main-content">
    <section class="wrapper">
        <div class="row mt">
            <div class="col-lg-12">
                <div class="content-panel">
                    <h4><i class="fa fa-directory"></i> 所有评论
                        <a target="_blank" class="btn btn-success pull-right" href="comment.php?act=downfile" style="margin-left: 5px;">
                            模板下载
                        </a>
                        <a href="javascript:;" class="btn btn-success pull-right file" style="margin-left: 5px;width: 150px;">
                            <input type="file" name="excel" id="excel-import" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">选择Excel文件导入
                        </a>
                        <a id="excel-import" class="btn btn-success pull-right" href="comment.php?act=edit">
                            增加评论
                        </a>
                    </h4>
                    <section id="unseen">
                        <table class="table table-bordered ">
                            <thead>
                            <tr>
                                <th>id</th>
                                <th>产品</th>
                                <th>姓名</th>
                                <th>添加时间</th>
                                <th width="40%">评论</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for g in goodsList %}
                            <tr class="{% if g.is_del==1 %}bg-danger{% endif %}">
                                <td>{{ g.comment_id }}</td>
                                <td>{{ g.title }}</td>
                                <td>{% if g.is_anonymous %} 匿名 {% else %} {{ g.name }} {% endif %}</td>
                                <td>{{ g.add_time }}</td>
                                <td>{{ g.content }}</td>
                                <td>
                                    
                                    {% if g.is_del ==1 %}
                                        <a class="btn btn-success" onclick="delproduct({{ g.comment_id }},0);"><i class="fa fa-edit"></i> 恢复 </a>
                                    {% else %}
                                        <a class="btn btn-primary" href="comment.php?comment_id={{ g.comment_id }}&act=edit"><i class="fa fa-edit"></i> 编辑</a>
                                        <a class="btn btn-danger"  onclick="delproduct({{ g.comment_id }},1);"><i class="fa fa-edit"></i> 删除 </a>
                                    {% endif %}
                                </td>
                            </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                        <div class="text-center">
                            {{ pageHtml|raw }}
                        </div>
                    </section>
                </div>
            </div>
        </div>
    </section>
</section>
    <script type="text/javascript">
        highlight_subnav('comment.php?');
        function delproduct(product_id,is_del) {

            var url = 'comment.php?' ;
            var json = {comment_id:product_id,is_del:is_del,act:"del"};
            $.ajax({
                url : url,
                data : json,
                type : "post",
                dataType:"json",

                success : function(data) {
                    if(data.ret)
                    {
                        location.reload()
                    }
                    else{
                        new PNotify({
                            title: '错误！！',
                            text: data.msg,
                            type: 'error',
                            addclass: 'stack-bar-top'
                        });
                    }

                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    alert(errorThrown);
                }

            });


        }
    </script>
    <script>
        $(function () {
            $('#excel-import').on('change',function () {
                //判断文件是否为空并上传
                if ($(this).val()) {
                    $(this).attr('disabled', true);
                    var formData = new FormData();
                    var name = $('#excel-import').val();
                    formData.append('file',$('#excel-import')[0].files[0]);
                    formData.append('name',name);
                    formData.append('act', 'excel-import');
                    $.ajax({
                        url: 'comment.php',
                        type : 'POST',
                        data : formData,
                        processData : false,
                        contentType : false,
                        success : function(json) {
                            var ret = JSON.parse(json);
                            if(ret.ret != 200)
                            {
                                new PNotify({
                                    title: '错误！！',
                                    text: ret.msg,
                                    type: 'error',
                                    addclass: 'stack-bar-top'
                                });return;
                            }
                            new PNotify({
                                title: '成功！',
                                text: ret.msg,
                                type: 'success',
                                addclass: 'stack-bar-top'
                            });
                            setTimeout(function () {
                                location.reload();
                            },2000);
                            $(this).attr('disabled', false);
                        },
                        error : function(json) {
                            console.log("error");
                            $(this).attr('disabled', true);
                        }
                    });
                };
            });
        });
    </script>
{% endblock %}